package list_.set_;

import java.util.HashSet;
import java.util.Objects;

/**
 * @description:
 * @Author yyp
 * @time 2022/3/23
 */
public class HashSetExercise {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(new test("a",1));
        hashSet.add(new test("b",1));
        hashSet.add(new test("c",1));
        hashSet.add(new test("d",1));
        hashSet.add(new test("e",1));
        hashSet.add(new test("f",1));
        System.out.println(hashSet);
    }
}

class test{
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "test{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        test test = (test) o;
        return age == test.age && Objects.equals(name, test.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public test(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

